package com.sgb.zhaocai.viewmodel;

import androidx.lifecycle.ViewModel;

import com.sgb.zhaocai.base.BaseApi;
import com.sgb.zhaocai.entity.RequestBean;
import com.sgb.zhaocai.entity.TenderExternalListEntity;
import com.sgb.zhaocai.view.fragment.WebSiteInvitedListFragment;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;
import java.util.List;

/**
 * Time:2021/12/17
 * AUTHOR:F_Q
 * Description:
 */
public class WebSiteInvitedListModel  extends ViewModel {
    WebSiteInvitedListFragment fragment;
    private boolean isLastPage;

    public void setActivity(WebSiteInvitedListFragment webSiteInvitedListFragment) {
        fragment = webSiteInvitedListFragment;
    }

    public void getWebSiteInvitedList(RequestBean requestbean){
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中", 0, true, null).setCanceledOnTouchOutside(false);
        BaseApi.getApi().gettenderExternalList(requestbean).enqueue(new ICallBack<BaseEntity<ListResponse<List<TenderExternalListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<TenderExternalListEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getState().equals(BaseApi.RESPONSE_OK)) {
                    isLastPage = data.getData().getCurrentPage() >= data.getData().getTotal();
                    fragment.setWebSiteBiddingList(data.getData().getList(), isLastPage);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    public void getWebSiteBiddingList(RequestBean requestbean) {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中", 0, true, null).setCanceledOnTouchOutside(false);
        BaseApi.getApi().getbidExternalList(requestbean).enqueue(new ICallBack<BaseEntity<ListResponse<List<TenderExternalListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<TenderExternalListEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getState().equals(BaseApi.RESPONSE_OK)) {
                    isLastPage = data.getData().getCurrentPage() >= data.getData().getTotal();
                    fragment.setWebSiteBiddingList(data.getData().getList(), isLastPage);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }
}
